# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer:
pkgname=ocaml-ppx_deriving
_pkgname=ppx_deriving
pkgver=4.2.1
pkgrel=3
pkgdesc="Type-driven code generation for OCaml"
url="https://github.com/ocaml-ppx/ppx_deriving"
arch="all !x86 !armhf !armv7 !s390x !mips !mips64"  # limited by ocaml aport
license="MIT"
depends="
	ocaml-migrate-parsetree
	ocaml-ppx_derivers
	ocaml-ppx_tools
	ocaml-result
	ocaml-runtime
	"
depends_dev="$pkgname=$pkgver-r$pkgrel"
checkdepends="ocaml-ounit"
makedepends="
	grep
	ocaml
	ocaml-compiler-libs
	ocaml-cppo-dev
	ocaml-cppo-ocamlbuild
	ocaml-findlib-dev
	ocaml-migrate-parsetree-dev
	ocaml-ocamlbuild-dev
	ocaml-ppx_derivers-dev
	ocaml-ppx_tools-dev
	ocaml-result-dev
	ocamlbuild
	opam
	"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/ocaml-ppx/$_pkgname/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	cd "$builddir"
	make
}

check() {
	cd "$builddir"
	make test
}

package() {
	cd "$builddir"

	opam-installer -i \
		--prefix="$pkgdir/usr" \
		--libdir="$pkgdir/usr/lib/ocaml" \
		--docdir="$builddir/.omit" \
		$_pkgname.install

	cd "$pkgdir"

	# Move executable to /usr/bin.
	mkdir -p usr/bin
	mv usr/lib/$_pkgname/ppx_deriving usr/bin/
	rmdir usr/lib/$_pkgname

	# Remove annotation files.
	rm -Rf "$pkgdir"/usr/lib/ocaml/$_pkgname/*.cmt*
}

dev() {
	local sitelib="usr/lib/ocaml/$_pkgname"
	default_dev

	cd "$pkgdir"

	mkdir -p "$subpkgdir"/usr
	mv usr/bin "$subpkgdir"/usr/

	ln -s ../../../bin/ppx_deriving \
		"$subpkgdir"/usr/lib/ocaml/$_pkgname/ppx_deriving

	cd "$pkgdir"/$sitelib
	mkdir -p "$subpkgdir"/$sitelib
	mv *.cmx *.cmxa *.mli "$subpkgdir"/$sitelib/
}

sha512sums="306cd62a5a2906782789967c9df3efd0f9fc31c4f59e39d3f678a0a24a5c48a210af8a28c9483a0f6ae174a36f79a00a2b1a0d547006c84fcc7a91101c2cd41b  ocaml-ppx_deriving-4.2.1.tar.gz"
